package yagwl.client.model;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

/**
 * Represents the event that is raised when an asynchronous RPI involving data
 * manipulation is completed. Data manipulation includes data fetch from server,
 * delete, update, etc.
 */
public class ItemListEvent extends GwtEvent<ItemListEvent.ItemListEventHandler> {

  public static final Type<ItemListEventHandler> TYPE = new Type<ItemListEventHandler>();
  private ItemListCache listCache;

  ItemListEvent(ItemListCache listCache) {
    super();
    this.listCache = listCache;
  }

  /**
   * Gets the cache manager that raised the event
   */
  public ItemListCache getListCache() {
    return listCache;
  }

  @Override
  protected void dispatch(ItemListEventHandler handler) {
    handler.onItemListEvent(this);
  }

  @Override
  public GwtEvent.Type<ItemListEventHandler> getAssociatedType() {
    return TYPE;
  }

  /**
   * Widgets interested in ItemListEvent must implement this interface.
   */
  public interface ItemListEventHandler extends EventHandler {
    public void onItemListEvent(ItemListEvent event);
  }
}
